package java6;

import java.util.Arrays;

public class ArrayIntegerStack implements IntegerStack{
		private Integer[] arrStack;
		public int top=0;
		public int capacity;
		public ArrayIntegerStack(int n){
			arrStack=new Integer[n];
		}
		public int size() {
			int num=0;
			if(arrStack.length==0)
			return 0;
			for (int i = 0; i < arrStack.length; i++) {
				if(arrStack[i]!=null){
					num++;
				}
			}
			return num;

		}
		
		public Integer push(Integer item) {
			if(item==null) 
				return null;
			if(top==this.capacity){
				throw new FullStackException();
			}
			return item;
		}
		
		public Integer pop() {
			if(top==0){
				throw new EmptyStackException();
			}
			return arrStack[--top];
		}
		
		public Integer peek() {
			if(top==0){
				throw new EmptyStackException();
			}
			return arrStack[top-1];
		}
		
		public boolean empty() {
			if(arrStack.length==0){
				return true;
			}
			return false;
		}
		@Override
		public String toString() {
			return Arrays.toString(arrStack);
		}
		
}
